//
//  LXNetworkTool.swift
//  zhibo
//
//  Created by Echo on 16/9/27.
//  Copyright © 2016年 Echo. All rights reserved.
//

import UIKit
import Alamofire

enum MethodType {
    case GET
    case POST
}

class LXNetworkTool {
    class func requestData(type : MethodType , URLString : String , params : [String : NSString]? = nil , finishedCallback : (result : AnyObject) -> ()){
        
        // 转成Method结构体下的值
        let method = type == .GET ? Method.GET : Method.POST
        
        Alamofire.request(method, URLString, parameters: params).responseJSON { (response) in
            // 获取可选类型结果
            guard let result = response.result.value else {
                print(response.result.error)
                return
            }
            
            // 将结果回调出去
            finishedCallback(result: result)
        }
        
    }
    

}
